﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DiyBook.Models;

namespace DiyBook.Controllers
{
    public class HomeController : Controller
    {
        BooksDB db = new BooksDB();
        public static string Bname; 
        public ActionResult Index()
        {
            var book = from m in db.Books
                       select m;     
            return View(book.ToList());
        }


        public ActionResult B_Search()
        {
            Bname = Request.Form["Bname"];
            if (Bname != null)
            {
                return RedirectToAction("B_SearchResult");
            }
            else
                return View();
        }

        public ActionResult B_SearchResult()
        {
            ViewData["Bname"] = "你查找的书名:" + Bname;
            var searchs = from m in db.Books
                          where Bname == m.bookName
                          select m;
            if (searchs == null)
                return View();
            else
                return View(searchs.ToList());
        }



        public ActionResult About()
        {
            return View();
        }
    }
}
